import { Navigate, useLocation } from "react-router-dom";

export const BeforeEach=(props)=>{
    const {children}=props
    const token=localStorage.getItem('token');
    const whitiList=['/login'];
    const {pathname}=useLocation();

    //已登录
    if(token && whitiList.includes(pathname)){
        return <Navigate to='/'></Navigate>
    }

    //未登录
    if(!token && !whitiList.includes(pathname)){
        return <Navigate to='/login'></Navigate>
    }
    return children
}